//
//  DHPlayerView.m
//  Moment
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "DHPlayerView.h"

@implementation DHPlayerView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
-(void)createView{
    _headImageView  = [UIImageView new];
    [self addSubview:_headImageView];
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(@(SCREEN_HEIGHT * 0.1));
        make.right.equalTo(@(-SCREEN_HEIGHT * 0.1));
        make.height.equalTo(_headImageView.mas_width);
    }];
    _titleLabel = [UILabel new];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_headImageView.mas_bottom).offset(SCREEN_HEIGHT * 0.05);
        make.left.equalTo(@(0));
        make.right.equalTo(@0);
        make.height.equalTo(@(SCREEN_HEIGHT * 0.05));
    }];
    _likeView = [UIImageView new];
    [self addSubview:_likeView];
    [_likeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(SCREEN_HEIGHT * 0.05);
        make.left.equalTo(_headImageView.mas_left).offset(SCREEN_HEIGHT * 0.05);
        make.height.and.width.equalTo(@(SCREEN_HEIGHT * 0.025));
    }];
    
    _likeView.image = [UIImage imageNamed:@"iconfont-xinxihuan00-2"];
    _likeLabel = [UILabel new];
    [self addSubview:_likeLabel];
    [_likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_likeView.mas_right).offset(3);
        make.top.equalTo(_likeView.mas_top);
        make.height.equalTo(_likeView.mas_height);
        make.width.equalTo(_likeView.mas_height).multipliedBy(3);
        
    }];
    _commentView = [UIImageView new];
    [self addSubview:_commentView];
    [_commentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_likeView.mas_top);
        make.left.equalTo(_likeView.mas_right).offset(SCREEN_HEIGHT * 0.15);
        make.width.height.mas_equalTo(_likeView.mas_height);
    }];
    _commentView.image = [UIImage imageNamed:@"iconfont-pinglun副本"];
    _commentLabel = [UILabel new];
    [self addSubview:_commentLabel];
    [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_commentView.mas_top);
        make.left.equalTo(_commentView.mas_right).offset(3);
        make.height.equalTo(_commentView.mas_height);
        make.width.equalTo(_commentView.mas_width).multipliedBy(3);
    }];
    _downLoadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_downLoadBtn setImage:[UIImage imageNamed:@"iconfont-xiazai"] forState:UIControlStateNormal];
    [self addSubview:_downLoadBtn];
    _mySlider = [[UISlider alloc]init];
    [self addSubview:_mySlider];
    [_mySlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_likeView.mas_bottom).offset(SCREEN_HEIGHT * 0.04);
        make.left.equalTo(@(SCREEN_HEIGHT * 0.13));
        make.right.equalTo(@(-SCREEN_HEIGHT * 0.18));
        make.height.equalTo(@(SCREEN_HEIGHT * 0.035));
    }];

    UIImage *slImage = [UIImage imageNamed:@"heikuai.png"];
    [_mySlider setThumbImage:slImage forState:UIControlStateNormal];
    //进度条左侧颜色
    self.mySlider.minimumTrackTintColor = [UIColor colorWithRed:60/255.0 green:60/255.0 blue:60/255.0 alpha:1.0];
    //进度条右侧颜色
    self.mySlider.maximumTrackTintColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
[_downLoadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(_mySlider.mas_left).offset(-SCREEN_WIDTH * 0.02);
    make.top.equalTo(_mySlider.mas_top);
    make.height.and.width.equalTo(_mySlider.mas_height);
}];
    _timeLabel = [UILabel new];
    [self addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_mySlider.mas_top);
        make.left.equalTo(_mySlider.mas_right).offset(SCREEN_WIDTH * 0.02);
        make.height.equalTo(_mySlider.mas_height);
        make.width.equalTo(@(SCREEN_WIDTH * 0.14));
    }];
    _timeLabel.backgroundColor = [UIColor greenColor];

}
-(void)setPlayerRadio:(DHREPlayeRadio *)playerRadio{
    if (_playerRadio != playerRadio) {
        _playerRadio = playerRadio;
    }
    NSURL *url = [NSURL URLWithString:_playerRadio.playinfo.imgUrl];
    [_headImageView sd_setImageWithURL:url placeholderImage:PLACEHOLDER_IMAGE];
    _titleLabel.text= _playerRadio.playinfo.title;
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.font = [UIFont systemFontOfSize:17];
    _likeLabel.text = [NSString stringWithFormat:@"%ld",_playerRadio.like];
    _likeLabel.font = [UIFont systemFontOfSize:8];
    _commentLabel.text = [NSString stringWithFormat:@"%ld",_playerRadio.comment];
    _commentLabel.font = [UIFont systemFontOfSize:8];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
